<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.grep.extra.factory.data.impl.TaskUrl"%>
<%@page import="com.grep.web.dto.TaskNumber"%>
<%@page import="com.grep.web.monitor.MonitorService"%>
<%@ include file="./common/ckeckuser.jsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.grep.web.IndexService,java.util.*"%> 
<%@ include file="./common/taglibs.jsp"%>
<%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
IndexService indexService = new IndexService();
List allSites = indexService.getAllSites();
String sitename = request.getParameter("sitename");
List<TaskUrl> tasknames = indexService.getTaskNames(sitename);
MonitorService ms = new MonitorService();
Map<String, List<TaskNumber>> taskNums = ms.getTaskNumbersByTasks(tasknames);
request.setAttribute("allSites",allSites);
request.setAttribute("tasknames",tasknames);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>首页</title>
		<link href="${base }/style/style.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript" src="${base }/style/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="${base }/style/highcharts.js"></script>
		<script type="text/javascript">
		<% if(taskNums != null && taskNums.size() > 0 && tasknames.size() > 0){ 
			String name = tasknames.get(0).getTaskName();
			List<TaskNumber> nums = taskNums.get(name);
			if(nums != null && nums.size() > 0){
				String categories = "";
				SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm");
				for(int i=nums.size()-1; i>=0; i--){
					Date d = nums.get(i).getTaskCollectDate();
					categories += "'" + sd.format(d) + "',";
				}
				categories = categories.substring(0, categories.length() -1);
				
				String series = "";
				
				for(String taskName : taskNums.keySet()){
					series += "{name: '" + taskName + "', data:[";
					List<TaskNumber> tns = taskNums.get(taskName);
					for(int i = tns.size()-1; i>=0; i--){
						series += tns.get(i).getTaskCollectNumber();
						if(i != 0){
							series += ",";
						}
					}
					series += "]},";
				}
				series = series.substring(0, series.length()-1);
		%>
		$(function () {
		    var chart;
		    $(document).ready(function() {
		        chart = new Highcharts.Chart({
		            chart: {
		                renderTo: 'container',
		                type: 'column'
		            },
		            title: {
		                text: '采集监控图'
		            },
		            subtitle: {
		                text: '来源: 采集程序'
		            },
		            xAxis: {
		                categories: [
		                <%=categories %>
		                ]
		            },
		            yAxis: {
		                min: 0,
		                title: {
		                    text: '采集数量'
		                }
		            },
		            legend: {
		                layout: 'vertical',
		                backgroundColor: '#FFFFFF',
		                align: 'left',
		                verticalAlign: 'top',
		                x: 100,
		                y: 70,
		                floating: true,
		                shadow: true
		            },
		            tooltip: {
		                formatter: function() {
		                    return ''+
		                        this.x +': '+ this.y +' 条';
		                }
		            },
		            plotOptions: {
		                column: {
		                    pointPadding: 0.2,
		                    borderWidth: 0
		                }
		            },
		                series: [
		                         <%=series %>
		                        ]
		        });
		    });
		    
		});
		<% }} %>
</script>
	</head>
	<body>
		<%@ include file="./common/header.jsp" %>  
		
		<div id="sider_left">
			<img src="${base }/images/leftbordertop.jpg" class="imgfloat" />
			<div id="sl_cont" class="siderborder">
				<span id="sltitle">采集网站<span style="float:right;font-size:12px;"><a href="new_website.jsp">新建</a></span></span>
				<ul>
					<!-- <li id="slxuan">4399游戏</li>
					<li class="slwei"><a href="#">7k7k游戏</a></li>
					<li class="slwei"><a href="#">安卓小游戏</a></li>
					 -->
					 <c:forEach var="site" items="${allSites}">
                       	<li class="slwei">
                       		<a href="${base }/index.jsp?sitename=${site.siteName}">${site.siteName }</a> 
                       	</li>
                      </c:forEach>
				</ul>
			</div>
			<img src="${base }/images/leftborderbuttom.jpg" class="imgfloat" />
		</div>
		<div id="sider_right">
			<img src="${base }/images/rightbordertop.jpg" class="imgfloat" />
			
			<div id="sr_cont" class="siderborder">
		<%
		 if(sitename ==null){ 
		%>
				请选择新建采集网站，或者依据右侧已有采集网站，点击选中，点击新建任务。
				网站采集任务建好后，点击配置，可对新建任务进行url配置 (目前一次只能增加单个url，如若需增加多个URL，暂时只能重做操作添加)
				网站采集任务，详细内容内有关于此任务的各项内容，如若需要修改任务配置URL，点击详细内容，便可对任务URL修改删除
				需要对任务采集测试，点击详细内容，进入页面，点击采集即可
			<%}
		  else{ %>
				<span style="color:#333; float:left; width:650px;">${param.sitename}采集情况监控</span>
				<div id="jiankong">
					<!-- <img src="images/jiankong.jpg" width="629" height="283"  title="4399游戏监控图" alt="4399游戏监控图"/>
					<span id="jktu"><samp>采集情况监控图</samp></span>-->
					<div id="container" style="width:650px; height:400px">
					</div>
					
				</div>
				<span style="color:#333; float:left; width:630px; margin-top:25px;">细分任务采集情况<span style="float:right;font-size:12px;"></span> </span>
				 <c:forEach var="task" items="${tasknames}">
				 	<ul class="xfrw">
						<li class="xfrw_title">点击查看<a href="${base }/monitor/taskmonitor.jsp?taskid=${task.id}&taskname=${task.taskName}" >${task.taskName}任务</a>监控图</li>
					</ul>
                </c:forEach>
			<%} %>	
				<!-- <ul class="xfrw">
					<li class="xfrw_title">策略类任务</li>
					<li class="xfrw_look"><a href="#">查看监控图</a></li>
				</ul>
				<ul class="xfrw">
					<li class="xfrw_title">益智类任务</li>
					<li class="xfrw_look"><a href="#">查看监控图</a></li>
				</ul> -->
			</div>
			<img src="${base }/images/rightborderbuttom.jpg" class="imgfloat" />
		</div>
	</body>
</html>